package utils

import (
	"fmt"
	"gopkg.in/ini.v1"
	"os"
)

var(
	AppMode string
	HttpPort string

	Db string
	DbHost string
	DbPort string
	DbUser string
	DbPassword string
	DbName string
)

func init(){
	file,err :=ini.Load("config/config.ini")
	if err !=nil{
		fmt.Println("配置文件读取失败，请检查文件路径和本文格式",err)
		os.Exit(1)
	}

	LoadServer(file)
	LoadData(file)
}

func LoadServer(file *ini.File){
	AppMode = file.Section("server").Key("AppMode").MustString("debug")
	HttpPort = file.Section("server").Key("HttpPort").MustString("3000")
}

func LoadData(file *ini.File){
	Db  = file.Section("server").Key("Db").MustString("mysql")
	DbHost = file.Section("server").Key("DbHost").MustString("localhost")
	DbPort = file.Section("server").Key("DbPort").MustString("3306")
	DbUser = file.Section("server").Key("DbUser").MustString("root")
	DbPassword = file.Section("server").Key("DbPassword").MustString("passwd123")
	DbName = file.Section("server").Key("DbName").MustString("ginblog")

}
